//
//  UIImageView+WebImage.swift
//  CustomWeiBo
//
//  Created by laiqiang on 21/6/2.
//  Copyright © 2021年 laiqiang. All rights reserved.
//

import Foundation

import SDWebImage

extension UIImageView {//avatarImage

    //isavatar 是否头像
    func wb_setimage(urlstring:String?, placeholderImage:UIImage? ,isavatar:Bool = false){

        guard let urlstring = urlstring,
            let url = URL.init(string: urlstring) else {
            image = placeholderImage
            return
        }
        
        sd_setImage(with: url, placeholderImage: placeholderImage, options: [], progress: nil) { [weak self] (image, _, _, _) in
            
            if isavatar {
              self?.image = image?.avatarImage(image: image!, size:self?.bounds.size)
            }
            else{
                self?.image = image
            }
        }
    }
}


